class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        n1, n2 = collections.Counter(nums1), collections.Counter(nums2)
        res = []

        for i in n1:
          # i 是键，即 nums1 中的元素
          # tmp是最少出现次数
            tmp = min(n1[i], n2[i])
            # 注意是while
            while tmp>0:
                res.append(i)
                tmp-=1
        return res
